#include "Settings.h"

///Copyright (c) 2009-2010 T. Klepzig 

Settings::Data data;

Settings::Data* Settings::GetData()
{
	return &data;
}


bool Settings::Save()
{
	BinaryFileHelper bfh("settings.dat", ios::out | ios::binary);

	if (!bfh)
	{
		bfh.Close();
		return false;
	}

	bfh.Exceptions(ios::failbit|ios::badbit);

	try
	{
		#pragma region KeyLock
				
		bfh.Write((char*)&data.KeyLockData,sizeof(data.KeyLockData));

		#pragma endregion

		bfh.Close();
	}
	catch(...)
	{
		bfh.Close();
		return false;
	}

	return true;
}

bool Settings::Load()
{

	BinaryFileHelper bfh("settings.dat", ios::in | ios::binary);

	if (!bfh)
	{
		bfh.Close();
		return false;
	}
	
	bfh.Exceptions(ios::failbit | ios::badbit);

	try
	{
		#pragma region KeyLock
				
		bfh.Read((char*)&data.KeyLockData,sizeof(data.KeyLockData));

		#pragma endregion

		bfh.Close();
	}
	catch(...)
	{
		bfh.Close();
		return false;
	}

	return true;
}
